< previous page page_582 next page >

Page 582
Continued
Listing 26.2
    '***********************
    '* SEEKING A DEALER ID *
    '***********************
    '  The IDIndex index is based on the DealerID field.

    'Set the recordset's index to the ID index
    rsDealers.Index = "IDIndex"

    'Look for dealer number 9534
    rsDealers.Seek "=", 9534

    'Display information or "Not Found" message as appropriate
    If rsDealers.NoMatch Then
       MsgBox "Not Found"
    Else
       MsgBox rsDealers!LastName & ", " & rsDealers!FirstName
    End If

    '*************************
    '* SEEKING A DEALER NAME *
    '*************************
    '  The NameIndex index is based on the
    '    LastName and FirstName fields.

    'Set the recordset's index to the name index
    rsDealers.Index = "NameIndex"

    'Look for dealer named "Barbara Austin"
    rsDealers.Seek "=", "Austin", "Barbara"

    'Display information or "Not Found" message as appropriate
    If rsDealers.NoMatch Then
       MsgBox "Not Found"
    Else
       MsgBox rsDealers!LastName & ", " & rsDealers!FirstName
    End If
You must carefully plan for one behavior of the Seek method. When the Seek method uses the comparison operators =, >=, >, or <>, Seek starts with the first record for the current index and scans forward through the index to find the first matching occurrence. If the comparison operator is < or <=, Seek starts with the last record in the table and scans backward through the table. If the index has unique values for each record, this search order presents no problem. However, if duplicate index values exist for the key fields being specified, the record found depends on the comparison operator and the sort order of the index. Figure 26.5 shows a table of first and last names indexed on last name and then first name. The table on the left is indexed in ascending order; the table on the right is indexed in descending order. Table 26.4 shows the results of different Seek operations that can be performed on this table.

 
< previous page page_582 next page >